package com.cmbyc.todolist.controller;


import com.cmbyc.todolist.VO.UpdateUserInfoQuery;
import com.cmbyc.todolist.VO.UserInfoVO;
import com.cmbyc.todolist.VO.UserShowVO;
import com.cmbyc.todolist.service.UserInfoService;
import com.cmbyc.todolist.utils.Result;
import com.cmbyc.todolist.utils.Token.PassToken;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author CYF
 * @since 2022-01-02
 */
@RestController
@RequestMapping("/user-info")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;



    // 登录
    @PassToken
    @PostMapping("/login")
    public Result login(@RequestBody UserInfoVO userInfoVO, HttpServletResponse response,HttpServletRequest request) {
        return userInfoService.login(userInfoVO, response,request);
    }

    /***
     * 这个请求需要验证token才能访问
     * @return String 返回类型
     */
    @PostMapping("/findUser")
    public Result findUser(@RequestBody UserInfoVO userInfoVO) {
        return userInfoService.findUser(userInfoVO);
    }

    @PostMapping("/logout")
    public Result logout(HttpServletResponse httpServletResponse, HttpServletRequest httpServletRequest) {
        return userInfoService.logout(httpServletResponse, httpServletRequest);
    }

    @PassToken
    @PostMapping("/register")
    public Result register(@RequestBody UserInfoVO userInfoVO) {
        return userInfoService.register(userInfoVO);
    }

    @PassToken
    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody UserInfoVO userInfoVO,HttpServletRequest request) {
        return userInfoService.updatePassword(userInfoVO,request);
    }

    @PassToken
    @PostMapping("/validationEmail")
    public Result validationEmail(@RequestBody UserInfoVO userInfoVO,HttpServletRequest request) {
        return userInfoService.validationEmail(userInfoVO,request);
    }

    @ApiOperation("用户信息显示")
    @GetMapping("/single")
    public UserShowVO userShow(String bId) {
        return userInfoService.userShow(bId);
    }

    @ApiOperation("用户名或密码修改")
    @GetMapping("/update/user/info")
    public Result updateUserInfo(UpdateUserInfoQuery query){
        return userInfoService.updateUserInfo(query);
    }

}
